import 'package:xws/helpers/as_t.dart';
import 'package:xws/res/images.dart';

import 'comment.dart';

/// 回复对象
class ReplyObj extends Comments {
  ReplyObj({
    final String? id,
    final String? goodsId,
    final String? pid,
    final String? userId,
    required String nickName,
    final String? avatarUrl,
    required String createdAt,
    final String? content,
  }) : super(
          id: id,
          goodsId: goodsId,
          pid: pid,
          userId: userId,
          nickName: nickName,
          avatarUrl: avatarUrl,
          createdAt: createdAt,
          content: content,
        );

  factory ReplyObj.fromJson(Map<String, dynamic> jsonRes) {
    // final List<Object>? replyList =
    //     jsonRes['replyList'] is List ? <Object>[] : null;
    // if (replyList != null) {
    //   for (final dynamic item in jsonRes['replyList']!) {
    //     if (item != null) {
    //       replyList.add(asT<Object>(item));
    //     }
    //   }
    // }
    String _avatarUrl = asT<String>(jsonRes['avatarUrl']);
    if (_avatarUrl.isEmpty) _avatarUrl = R.defHeader;

    return ReplyObj(
      id: asT<String?>(jsonRes['id']),
      goodsId: asT<String?>(jsonRes['goodsId']),
      pid: asT<String?>(jsonRes['pid']),
      userId: asT<String?>(jsonRes['userId']),
      nickName: asT<String>(jsonRes['nickName']),
      avatarUrl: _avatarUrl,
      createdAt: asT<String>(jsonRes['createdAt']),
      content: asT<String?>(jsonRes['content']),
      // replyList: replyList,
    );
  }

  // final List<Object>? replyList;
}
